#include "common.hpp"
//在读文件中需要创建管道文件
//此时读文件只需要读取管道文件的数据
int main()
{
    //创建管道文件
    Fifo fifo(Path);

    //打开管道文件
    int fd = open(Path, O_RDONLY);
    if(fd == -1)
    {
        cout << "use read open pipe file fail" << endl;
        cerr << "errno : " << errno << ", strerror : " << strerror(errno) << endl;
        exit(-1);
    }
    cout << "read open pipe file success" << endl;
    char buffer[1024] = "\0";
    //开始读取
    while(true)
    {
        ssize_t n = read(fd, buffer, sizeof(buffer) - 1);
       
        if(n == -1)
        {
            cout << "read pipe file fail" << endl;
            cerr << "errno : " << errno << ", strerror : " << strerror(errno) << endl;
            exit(-1);
        }
        else if(n == 0)
        {
            cout << "write success exit" << endl;
            break;
        }

        buffer[sizeof(buffer)] = '\0';
        cout << "Get message: " << buffer << endl;
    }

    close(fd);
    return 0;
}